//
//  BELManagement.h
//  JiuLe
//
//  Created by 黄鑫 on 2016/11/3.
//  Copyright © 2016年 Fine. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <CoreBluetooth/CoreBluetooth.h>
#import <CoreBluetooth/CBService.h>

typedef NS_ENUM(NSInteger, BluetoothStatus) {
    BluetoothStatusPhoneNotOpen = 0,    //手机蓝牙未打开
    BluetoothStatusPhoneOpen,           //手机蓝牙已打开
    BluetoothStatusEquipmentNotOpen,    //设备蓝牙未打开
    BluetoothStatusEquipmentOpen,       //设备蓝牙已打开
    BluetoothStatusConnection,          //蓝牙连接成功
    BluetoothStatusConnectionFailed,    //蓝牙连接失败
    BluetoothStatusConnectionTimeOut,   //蓝牙连接超时
};

@protocol BELManagementDelegate <NSObject>
@optional
- (void)backBluetoothStatus;

-(void) onDiscoverPeripheral:(nonnull NSArray *)arrDiscoverPeripheral;
-(void) onConnected:(BOOL)status;
@end

@interface BELManagement : NSObject <CBCentralManagerDelegate, CBPeripheralDelegate> {
}
@property (assign, nonatomic, nonnull) id<BELManagementDelegate> delegate;
@property (strong, nonatomic, nonnull) NSMutableArray *peripherals;
@property (strong, nonatomic, nonnull) CBCentralManager *cManager;  //中心设备(手机应用)  ：用来扫描服务器端，请求连接并获取服务端提供的数据
@property (strong, nonatomic, nonnull) CBPeripheral *cPeripheral;   //外围设备(蓝牙手表等) ：它主要是广播自己并提供服务
@property (assign, nonatomic) BluetoothStatus bluetoothStatus;
+ (nullable instancetype)sharedInstance;

//创建中心设备
- (void)creatCentralManagement;

//搜索外围设备
- (void)searchPeripheral:(int)timeout;

//停止搜索外围设备
- (void)stopSearch;

- (BOOL)checkBluetoothStatus;

@end
